package org.crazyit.activiti_d2._2_C3P0Config;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.activiti.engine.ProcessEngineConfiguration;
import org.apache.commons.dbcp.BasicDataSource;

import java.beans.PropertyVetoException;
import java.sql.SQLException;

public class C3P0Config_2 {

    public static void main(String[] args) throws SQLException, PropertyVetoException {

       //1. 创建DBCP 数据源
        ComboPooledDataSource ds = new ComboPooledDataSource();

        //2. 设置JDBC 连接的各个属性
        ds.setUser("root");
        ds.setPassword("root");
        ds.setJdbcUrl("jdbc:mysql://localhost:3306/tsign");
        ds.setDriverClass("com.mysql.jdbc.Driver");

        //3. 验证是否连接成功
        System.out.println(ds.getConnection().getMetaData().getDriverName());

        //4. 读取Activiti 配置文件
        ProcessEngineConfiguration config = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("dbcp-coding.xml");

        //5. 为ProcessEngineConfiguration 设置dataSource 属性
        config.setDataSource(ds);

        //6. 验证是否设置完毕
        System.out.println(config.getDataSource().getClass().getName());

    }

}
